module utils.log;

import std.cstream;
import std.stream;
public import std.string: format;

enum ViewType {
    CONSOLE,
    UI
}

enum Severity {
    QUESTION,
    INFORMATION,
    WARNING,
    CRITICAL
}

class Log {
    private this() {
    }

    private ~this() {
        dout.flush();
        derr.flush();
    }

    public static void message(in string text, Severity severity = Severity.INFORMATION, ViewType viewType = ViewType.CONSOLE) shared {
        if (viewType == ViewType.CONSOLE) {
            Stream stream;
            switch (severity) {
            case Severity.INFORMATION:
                stream = dout;
                break;
            case Severity.WARNING:
            case Severity.CRITICAL:
                stream = derr;
                break;
            default:
                throw new Exception("Wrong severity");
            }
            synchronized (stream) {
                stream.writeLine(format("%s", text));
            //   stream.flush();
            }
        } else {
        }
    }
}
